//
//  TMCourseCollectCell.m
//  国学商家管理
//
//  Created by Tao Li on 2018/6/26.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "TMCourseCollectCell.h"
#import "TMCourseItemCell.h"
//#import "TMClassDetailController.h"
#import "TMShopCourseModel.h"
@interface TMCourseCollectCell()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, assign) CGSize itemSize;

@end
@implementation TMCourseCollectCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setListArray:(NSArray *)listArray{
    _listArray = listArray;
    [self.itemCollection reloadData];
}
- (void)setItemCollection:(UICollectionView *)itemCollection{
    _itemCollection = itemCollection;
    [_itemCollection registerNib:[UINib nibWithNibName:@"TMCourseItemCell" bundle:nil] forCellWithReuseIdentifier:@"TMCourseItemCell"];
    _itemCollection.delegate = self;
    _itemCollection.dataSource = self;
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.minimumLineSpacing = 12*kWindowW/375;
    flowLayout.minimumInteritemSpacing = 6*kWindowW/375;
    _itemSize = CGSizeMake(118 * kWindowW /375, 110 * kWindowW /375);
    _itemCollection.collectionViewLayout = flowLayout;
    _itemCollection.scrollEnabled = NO;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return self.itemSize;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0, 0, 0, 0);
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.listArray.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    TMCourseItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TMCourseItemCell" forIndexPath:indexPath];
    for (NSObject *obj in self.listArray) {
        if ([obj isKindOfClass:[TMShopCourseModel class] ]) {
            cell.courseModel = self.listArray[indexPath.item];
        }
        if ([obj isKindOfClass:[TMShopTeacherModel class] ]) {
            cell.teacherModel = self.listArray[indexPath.item];
        }
        
    }
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (self.block) {
        self.block(indexPath.item);
    }
}
@end
